import { defineStore } from 'pinia'
import request from '@/utils/request'

export const useQuestionnaireStore = defineStore('questionnaire', {
  state: () => ({
    submittedQuestionnaires: new Set()
  }),

  actions: {
    async loadSubmittedQuestionnaires() {
      try {
        const res = await request.get('/api/questionnaire/my-submissions')
        if (res.code === 200) {
          this.submittedQuestionnaires = new Set(res.data.map(item => item.questionnaireId))
        }
      } catch (error) {
        if (error.response?.status !== 401) {
          console.error('获取已提交问卷失败:', error)
        }
      }
    },

    isSubmitted(questionnaireId) {
      return this.submittedQuestionnaires.has(questionnaireId)
    }
  }
}) 